package com.demo.controller;

import com.demo.dto.DepartmentDTO;
import com.demo.dto.DepartmentPageQueryDTO;
import com.demo.dto.StudentDTO;
import com.demo.dto.StudentPageQueryDTO;
import com.demo.result.PageResult;
import com.demo.result.Result;
import com.demo.service.DepartmentService;
import com.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin(origins = "http://localhost:8080")
@RequestMapping("/instructor/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    //新增学生信息
    @PostMapping
    public Result save(@RequestBody StudentDTO studentDTO) {
        studentService.save(studentDTO);
        return Result.success();
    }

    //分页查询
    @PostMapping("/page")
    public Result<PageResult> page(@RequestBody StudentPageQueryDTO studentPageQueryDTO) {
        System.out.println(studentPageQueryDTO);
        PageResult pageResult = studentService.pageQuery(studentPageQueryDTO);
        return Result.success(pageResult);
    }

    //删除学生信息
    @DeleteMapping("/id")
    public Result deleteById(@RequestParam("stuID") String stuID){
        studentService.deleteById(stuID);
        return Result.success();
    }

    /**
     * 批量删除
     * @param stuIDs
     * @return
     */
    @DeleteMapping
    public Result delete(@RequestBody String[] stuIDs){
        System.out.println(stuIDs);
        studentService.delete(stuIDs);
        return Result.success();
    }

    //修改学生信息
    @PutMapping
    public Result update(@RequestBody StudentDTO studentDTO){
        studentService.update(studentDTO);
        return Result.success();
    }
}
